package lormi.meipin.controller.api;

import lormi.meipin.common.Result;
import lormi.meipin.controller.BaseController;
import lormi.meipin.entity.Environment;
import lormi.meipin.exception.LMException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 美聘商家工作环境
 * */
@RestController
@RequestMapping(value="v2/environment",method=RequestMethod.POST,produces = "application/json; charset=utf-8")
public class EnvironmentController extends BaseController{

	/**
	 * 添加公司工作环境
	 * @param userid 用户ID
	 * @param imgurl  工作环境图片地址
	 * */
	@Valid
	@RequestMapping("add")
	public String select(@NotNull(message="100033") @RequestParam(value="userid",required=false) Integer userid,
			@NotNull(message="100033") @RequestParam(value="imgurl",required=false) String imgurl) throws LMException{
		
		return Result.success(environmentService.addOne(new Environment(userid,imgurl)));
	}
	
	/**
	 * 修改一张工作环境图片
	 * @Param id 环境图片ID
	 * @Param imgurl 环境图片地址
	 * */
	@Valid
	@RequestMapping("edit")
	public String editEnvironment(@NotNull(message="100033") @RequestParam(value="userid",required=false) Integer userid,
			@NotNull(message="100033") @RequestParam(value="id",required=false) Integer id,
			@NotNull(message="100033") @RequestParam(value="imgurl",required=false) String imgurl) throws LMException{
		environmentService.editUrl(new Environment(id,userid,imgurl));
		return Result.success();
	}
	
	/**
	 * 删除一张工作环境图片
	 * @Param id 环境图片ID
	 * */
	@Valid
	@RequestMapping("delete")
	public String delEnvironment(@NotNull(message="100033") @RequestParam(value="id",required=false) Integer id) throws LMException{
		environmentService.delOneById(id);
		return Result.success();
	}
	
	
	/**
	 * 获取所有工作环境图片
	 * @Param userid 用户ID
	 * */
	@RequestMapping("list")
	public String getEnvironments(@NotNull(message="100033") @RequestParam(value="userid",required=false)Integer userid) throws LMException{
		
		return Result.success(environmentService.getAll(userid));
	}

}
